using System;
using System.Configuration;
using System.IO;
using System.Xml;
using FormsGenerator.Xml;

namespace FormsGenerator 
{
	/// <summary>
	/// Summary description for Global.
	/// </summary>
	public class Global : System.Web.HttpApplication
	{
		public Global()
		{
			InitializeComponent();
		}	
		
		protected void Application_Start(Object sender, EventArgs e)
		{
			XmlDocument FormElements = XmlHandler.GetFormElements();	
			Application["FormElements"] = FormElements;
			try
			{
                if (bool.Parse(ConfigurationManager.AppSettings["EnableHTMLEditor"]))
				{
                    StreamReader readEditorInitScript = new StreamReader(Server.MapPath(ConfigurationManager.AppSettings["HTMLEditorInitialScript"]));
					string initScript = readEditorInitScript.ReadToEnd();
					readEditorInitScript.Close();
					Application["HTMLEditorInitialScript"] = initScript;
				}
			}
			catch (IOException ioex)
			{
                throw new IOException("Couldn read file: " + ConfigurationManager.AppSettings["HTMLEditorInitialScript"], ioex);
			}
			catch(Exception ex)
			{
				throw new ApplicationException("Please add key \"EnableHTMLEditor\" to web.config i the appSettings section", ex );
			}
		}
 
		protected void Session_Start(Object sender, EventArgs e)
		{

		}

		protected void Application_BeginRequest(Object sender, EventArgs e)
		{

		}

		protected void Application_EndRequest(Object sender, EventArgs e)
		{

		}

		protected void Application_AuthenticateRequest(Object sender, EventArgs e)
		{

		}

		protected void Application_Error(Object sender, EventArgs e)
		{

		}

		protected void Session_End(Object sender, EventArgs e)
		{

		}

		protected void Application_End(Object sender, EventArgs e)
		{

		}
			
		#region Web Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
		}
		#endregion
	}
}

